//package cc.vv.baselibrary.adapter.deliveryAddress;
//
//import android.content.Context;
//import android.content.Intent;
//import android.content.res.Resources;
//import android.graphics.drawable.BitmapDrawable;
//import android.graphics.drawable.Drawable;
//import android.graphics.drawable.StateListDrawable;
//import android.os.Handler;
//import android.os.Message;
//import android.text.Html;
//import android.text.TextUtils;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.CheckBox;
//import android.widget.TextView;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import cc.vv.baselibrary.R;
//import cc.vv.baselibrary.activity.deliveryAddress.AddOrEditorDeliveryAddressActivity;
//import cc.vv.baselibrary.activity.deliveryAddress.ManageDeliveryAddressActivity;
//import cc.vv.baselibrary.adapter.LKBaseAdapter;
//import cc.vv.baselibrary.db.daTable.DeliveryAddressBean;
//import cc.vv.baselibrary.global.BCSharePreKey;
//import cc.vv.baselibrary.global.BaseLibHandlerKey;
//import cc.vv.baselibrary.util.ColorUtil;
//import cc.vv.baselibrary.util.LKLogUtil;
//import cc.vv.baselibrary.util.LKPrefUtil;
//import cc.vv.baselibrary.util.StringProcessingUtil;
//import cc.vv.baselibrary.view.JniCancelAndConfirmDialog;
//
//
///**
// * 管理收货地址列表适配器
// * Created by sun.li on 2017/7/3.
// *
// * @author sun.li
// */
//public class ManageDeliveryAddressAdapter extends LKBaseAdapter<DeliveryAddressBean> {
//
//    private Handler mHandler;
//
//    public ManageDeliveryAddressAdapter(Context context, List<DeliveryAddressBean> deliveryAddressBeanList, Handler mHandler) {
//        super(context, (ArrayList<DeliveryAddressBean>) deliveryAddressBeanList);
//        this.mHandler = mHandler;
//    }
//
//    @Override
//    protected View lpgetView(int position, View convertView, ViewGroup parent) {
//        ViewHolder viewHolder;
//        if (convertView == null) {
//            viewHolder = new ViewHolder();
//            convertView = View.inflate(mContext, R.layout.layout_delivery_address_editer_item, null);
//            viewHolder.tv_daei_userName = convertView.findViewById(R.id.tv_daei_userName);
//            viewHolder.tv_daei_phone = convertView.findViewById(R.id.tv_daei_phone);
//            viewHolder.tv_daei_address = convertView.findViewById(R.id.tv_daei_address);
//            viewHolder.cb_daei_set_default_address = convertView.findViewById(R.id.cb_daei_set_default_address);
//            viewHolder.tv_daei_editor_address = convertView.findViewById(R.id.tv_daei_editor_address);
//            viewHolder.tv_daei_delete_address = convertView.findViewById(R.id.tv_daei_delete_address);
//
//            int anInt = LKPrefUtil.getInt(BCSharePreKey.THEME_MAIN_COLOR, ColorUtil.setBCColor(R.color.color_28BFA9));
//            if (anInt != 0) {
//                viewHolder.tv_daei_delete_address.setTextColor(anInt);
//            }
//
//            String selectIcon = LKPrefUtil.getString(BCSharePreKey.SELECT_SMALL_ICON, "");
//            if (!TextUtils.isEmpty(selectIcon)) {
//                StateListDrawable drawable = null;
//                try {
//                    drawable = new StateListDrawable();
//                    Drawable hmDDrawable = Drawable.createFromPath(selectIcon);
//                    Drawable normalDrawable = mContext.getResources().getDrawable(R.mipmap.icon_pay_check_no);
//                    if (hmDDrawable != null && normalDrawable != null) {
//                        drawable.addState(new int[]{android.R.attr.state_checked}, hmDDrawable);
//                        drawable.addState(new int[]{-android.R.attr.state_checked}, normalDrawable);
//                    }
//                } catch (Resources.NotFoundException e) {
//                    e.printStackTrace();
//                }
//                viewHolder.cb_daei_set_default_address.setBackground(drawable);
//            }
//            convertView.setTag(viewHolder);
//        } else {
//            viewHolder = (ViewHolder) convertView.getTag();
//        }
//        initViewEvent(position, viewHolder);
//
//        return convertView;
//    }
//
//    private void initViewEvent(final int i, ViewHolder viewHolder) {
//        if (viewHolder != null && mObjList != null) {
//            final DeliveryAddressBean deliveryAddressBean = mObjList.get(i);
//            if (deliveryAddressBean != null) {
//                /*设置收货人名称*/
//                if (!TextUtils.isEmpty(deliveryAddressBean.getUserName())) {
//                    viewHolder.tv_daei_userName.setText(deliveryAddressBean.getUserName());
//                }
//                /*设置手机号码*/
//                if (!TextUtils.isEmpty(deliveryAddressBean.getPhone())) {
//                    viewHolder.tv_daei_phone.setText(StringProcessingUtil.setNumFormat(deliveryAddressBean.getPhone()));
//                }
//                /*设置收货地址*/
//                String address = "";
//                if (!TextUtils.isEmpty(deliveryAddressBean.getLabel())) {
//                    address += "<font color=\"#28BFA9\">" + "[" + deliveryAddressBean.getLabel() + "]" + "</font>";
//                } else {
//                }
//                if (!TextUtils.isEmpty(deliveryAddressBean.getCity())) {
//                    address += deliveryAddressBean.getCity();
//                }
//                if (!TextUtils.isEmpty(deliveryAddressBean.getAddress())) {
//                    address += deliveryAddressBean.getAddress();
//                }
//                viewHolder.tv_daei_address.setText(Html.fromHtml(address));
//
//                viewHolder.cb_daei_set_default_address.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        //服务器接口数据
//                        setDefaultDeliveryAddress(deliveryAddressBean, i);
//                    }
//                });
//
//                if (deliveryAddressBean.isDefaultAddress()) {
////                        viewHolder.cb_daei_set_default_address.setButtonDrawable(R.mipmap.icon_address_selected);
//                    viewHolder.cb_daei_set_default_address.setChecked(true);
//                } else {
////                    viewHolder.cb_daei_set_default_address.setButtonDrawable(R.mipmap.icon_address_uncheck);
//                    viewHolder.cb_daei_set_default_address.setChecked(false);
//                }
//
//                viewHolder.tv_daei_editor_address.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        Intent intent = new Intent(mContext, AddOrEditorDeliveryAddressActivity.class);
//                        intent.putExtra(AddOrEditorDeliveryAddressActivity.ManageOrSelectSkipLogoKey, ManageDeliveryAddressActivity.ManageDeliveryAddressActivityLogo_update);
//                        intent.putExtra(AddOrEditorDeliveryAddressActivity.AddressEditorLogoKey, deliveryAddressBean);
//                        mContext.startActivity(intent);
//                    }
//                });
//
//                viewHolder.tv_daei_delete_address.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View view) {
//                        JniCancelAndConfirmDialog dialog = new JniCancelAndConfirmDialog(mContext);
//                        dialog.setContent(mContext.getString(R.string.str_mdaa_whether_delete_address));
//                        dialog.setConfirmBtnText("删除");
//                        dialog.setEventInterface(new JniCancelAndConfirmDialog.EventInterface() {
//                            @Override
//                            public void cancelOnClick() {
//                            }
//
//                            @Override
//                            public void confirmOnClick() {
//                                try {
//                                    //删除收货地址
//                                    delDeliveryAddress(deliveryAddressBean, i);
//                                    //本地假数据逻辑
//                                } catch (Exception e) {
//                                    LKLogUtil.e(e.getMessage(), e);
//                                }
//                            }
//                        });
//                        dialog.show();
//                    }
//                });
//            }
//        }
//    }
//
//    private class ViewHolder {
//
//        /**
//         * 收货人名称
//         */
//        private TextView tv_daei_userName;
//
//        /**
//         * 收货人电话
//         */
//        private TextView tv_daei_phone;
//
//        /**
//         * 地址信息
//         */
//        private TextView tv_daei_address;
//
//        /**
//         * 设置默认地址
//         */
//        private CheckBox cb_daei_set_default_address;
//
//        /**
//         * 编辑地址按钮
//         */
//        private TextView tv_daei_editor_address;
//
//        /**
//         * 删除地址按钮
//         */
//        private TextView tv_daei_delete_address;
//    }
//
//
//    /**
//     * 设为默认收货地址
//     */
//    private void setDefaultDeliveryAddress(DeliveryAddressBean bean, int i) {
//        Message message = new Message();
//        message.arg2 = i;
//        message.obj = bean;
//        message.what = BaseLibHandlerKey.ADDRESSACTIVITY_SET_DEFAULT_ADDRESS;
//        mHandler.sendMessage(message);
//    }
//
//    /**
//     * 删除收货地址
//     */
//    private void delDeliveryAddress(DeliveryAddressBean bean, int i) {
//        Message message = new Message();
//        message.arg2 = i;
//        message.obj = bean;
//        message.what = BaseLibHandlerKey.ADDRESSACTIVITY_DEL_ADDRESS;
//        mHandler.sendMessage(message);
//    }
//}
